package com.lebron.kotlin.ui.model.impl

import com.lebron.kotlin.bean.movie.Subject
import com.lebron.kotlin.http.ApiCompleteListener
import com.lebron.kotlin.http.BaseObserver
import com.lebron.kotlin.http.DouBanApiManager
import com.lebron.kotlin.http.DouBanApiService
import com.lebron.kotlin.ui.model.MovieDetailModelI
import com.lebron.kotlin.utils.Constants
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * @Author lebron
 * @Date 18-8-2-上午9:58
 */
class MovieDetailModelImpl(val listener: ApiCompleteListener<Subject,Any>) : MovieDetailModelI{

    override fun getMovieSubject(id: String) {
        DouBanApiManager.createService(Constants.DOUBAN_URL,DouBanApiService::class.java)
                ?.getSubject(id)
                ?.subscribeOn(Schedulers.io())
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribe(object : BaseObserver<Subject>(){
                    override fun onNext(t: Subject) {
                        listener.onComplete(t)
                    }

                    override fun onError(e: Throwable) {
                       listener.onFailed(e.toString())
                    }
                })
    }
}

